<script type="text/javascript">
	//var tid = "";
	var listenerId = "";
	$(function () {
		$('#task-properties-accordion').accordion({
			onSelect: function (title, index) {
				if (title == 'General') {
					var pp = $('#task-properties-accordion').accordion('getSelected');
					if (pp) {
						pp.panel('refresh', 'taskGeneral.html');
					}
				} else if (title == 'Multi Instance') {
					var pp = $('#task-properties-accordion').accordion('getSelected');
					if (pp) {
						pp.panel('refresh', 'taskMultiInstance.html');
					}
				}
			}
		});
		_listener_win = $('#listener-win').window({
			//href:'${ctx}/wf/procdef/procdef!forTaskListenerConfig.action',   
			closed: true,
			//cache:false,
			draggable: false,
			collapsible: false,
			minimizable: false,
			maximizable: false,
			modal: true,
			shadow: true
		});
		$('#task-listeners-list').datagrid({
			title: "Execution Listeners",
			//url:'${ctx}/wf/procdef/procdef!search.action',//���ر�����ݵ�URL
			singleSelect: true,
			//width:500,
			height: 300,
			//idField:'id',
			//pagination:true,
			//pageSize:15,
			//pageNumber:1,
			//pageList:[10,15],
			rownumbers: true,
			//sortName:'id',
			//sortOrder:'asc',
			striped: true,
			toolbar: [{
				text: 'New',
				iconCls: 'icon-add',
				handler: function () {
					_listener_win.window('open');
					//_listener_frame.src="";
					_listener_win.window('refresh', 'executionListenerConfig.html');
					//alert(_listener_frame.document.body.innerHTML);
				}
			}]
		});

		populateTaskProperites();
	});
	function listenerActionBt(value, rowData, rowIndex) {
		var id = rowData.id;
		var e = '<img onclick="editListener(\'' + id + '\')" src="image/edit.gif" title="�޸�" style="cursor:hand;"/>';
		var d = '<img onclick="deleteListener(\'' + id + '\')" src="image/delete.gif" title="ɾ��" style="cursor:hand;"/>';
		return e + '&nbsp;' + d;
	}
	function editListener(id) {
		listenerId = id;
		_listener_win.window('open');
		_listener_win.window('refresh', 'executionListenerConfig.html');
	}
	function deleteListener(id) {
		task.deleteListener(id);
		loadTaskListeners();
	}
	function saveTaskProperties() {
		saveTaskGeneral();
		saveTaskMainConfig();
		if (typeof saveTaskMultiInstance == 'function')
			saveTaskMultiInstance();
		$.messager.alert('Info', '保存成功！', 'info');
	}
	function saveTaskMainConfig() {
		task.ruleName = $('#ruleName').val();
		task.inputVariable = $('#inputVariable').val();
		task.resultVariable = $('#resultVariable').val();
		if ($('#excludeYes').attr('checked'))
			task.excluded = true;
		if ($('#excludeNo').attr('checked'))
			task.excluded = false;
	}
	function populateTaskProperites() {
		loadTaskMainConfig();
		loadTaskListeners();
	}
	function loadTaskMainConfig() {
		$('#ruleName').val(task.ruleName);
		$('#inputVariable').val(task.inputVariable);
		$('#resultVariable').val(task.resultVariable);
		if (task.excluded)
			$('#excludeYes').attr('checked', true);
		else
			$('#excludeNo').attr('checked', true);
	}
	function loadTaskListeners() {
		var listeners = task.listeners;
		var listener_grid_rows = [];
		//alert(listeners.getSize());
		for (var i = 0;i < listeners.getSize();i++) {
			var listener = listeners.get(i);
			var nlistener = {
				id: listener.getId(),
				listenerImplimentation: listener.getServiceImplementation(),
				type: listener.serviceType,
				event: listener.event,
				fields: listener.getFieldsString(),
				action: ''
			};
			listener_grid_rows[i] = nlistener;
		};
		//alert(listener_grid_rows);
		var listener_grid_data = {
			total: listeners.getSize(),
			rows: listener_grid_rows
		};
		$('#task-listeners-list').datagrid('loadData', listener_grid_data);
	}
//-->
</script>
<div id="task-properties-layout" class="easyui-layout" fit="true">
	<div id="task-properties-toolbar-panel" region="north" border="false" style="height:30px;background:#E1F0F2;">
		<a href="##" id="sb2" class="easyui-linkbutton" plain="true" iconCls="icon-save"
			onclick="saveTaskProperties()">Save</a>
	</div>
	<div id="task-properties-panel" region="center" border="true">
		<div id="task-properties-accordion" class="easyui-accordion" fit="true" border="false">
			<div id="general" title="General" selected="true" class="properties-menu">

			</div>
			<div id="mainConfig" title="Main Config" class="properties-menu">
				<table id="main-properties">
					<tr>
						<td align="right">Rule Name:</td>
						<td>
							<input type="text" id="ruleName" name="ruleName" size="50" />
						</td>
					</tr>
					<tr>
						<td align="right">Input Variable:</td>
						<td>
							<input type="text" id="inputVariable" name="inputVariable" size="50" />
						</td>
					</tr>
					<tr>
						<td align="right">Excluded:</td>
						<td>
							<input type="radio" id="excludeYes" name="excluded" value="true" />Yes
							<input type="radio" id="excludeNo" name="excluded" value="false" checked />No
						</td>
					</tr>
					<tr>
						<td align="right">Result Variable:</td>
						<td>
							<input type="text" id="resultVariable" name="resultVariable" size="50" />
						</td>
					</tr>
				</table>
			</div>
			<div id="listeners" title="Listeners" style="overflow: hidden;">
				<table id="task-listeners-list">
					<thead>
						<tr>
							<th field="listenerImplimentation" width="200" align="middle" sortable="false">Listener
								Implimentation</th>
							<th field="type" width="70" align="middle" sortable="false">Type</th>
							<th field="event" width="70" align="middle" sortable="false">Event</th>
							<th field="fields" width="100" align="middle">Fields</th>
							<th field="action" width="100" align="middle" formatter="listenerActionBt">Action</th>
						</tr>
					</thead>
				</table>
			</div>
			<div id="multi-instance" title="Multi Instance" class="properties-menu">

			</div>
		</div>
	</div>
</div>